﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
</head>
<body class="layui-padding-3">
    <h3 style="color: #34c38f">
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/ProductionTasks/ProductionTasksSearch'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;生产任务&nbsp;(<i class="layui-icon layui-icon-backspace"></i>)
    </h3>
    <hr style="color: #34c38f" />
    <form class="layui-form" action="">
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">任务编码</label>
                <div class="layui-input-block">
                    <input type="text" name="productiontasksCode" id="productiontasksCode" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">任务名称</label>
                <div class="layui-input-block">
                    <input type="text" name="productiontasksName" id="productiontasksName" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">任务类型</label>
                <div class="layui-input-inline">
                    <select name="taskTypeId" id="taskTypeId" lay-verify="required" lay-search lay-filter="demoselect">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">任务状态</label>
                <div class="layui-input-block">
                    <input type="text" name="isStatus" id="isStatus" value="新建" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">物料</label>
                <div class="layui-input-inline">
                    <select name="materialId" id="materialId" lay-verify="required" lay-search lay-filter="demoselect">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">物料规格</label>
                <div class="layui-input-block">
                    <input type="text" name="materialUnit" id="materialUnit" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">物料单位</label>
                <div class="layui-input-block">
                    <input type="text" name="materialSpecifications" id="materialSpecifications" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">生产数量</label>
                <div class="layui-input-block">
                    <input type="text" name="productionQuantity" id="productionQuantity" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">开工时间</label>
                <div class="layui-input-inline layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" name="startTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">完工时间</label>
                <div class="layui-input-inline layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" name="endTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>

            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">物料清单</label>
                <div class="layui-input-inline">
                    <select name="boMInformId" id="boMInformId" lay-verify="required" lay-search lay-filter="demo1select">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">物料清单版本</label>
                <div class="layui-input-block">
                    <input type="text" name="boMInformVersion" id="boMInformVersion" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">工艺路线</label>
                <div class="layui-input-inline">
                    <select name="processRouteId" id="processRouteId" lay-verify="required" lay-search lay-filter="demo2select">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">工艺路线版本</label>
                <div class="layui-input-block">
                    <input type="text" name="processVersion" id="processVersion" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">生产入库数量</label>
                <div class="layui-input-block">
                    <input type="text" readonly placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">生产退货数量</label>
                <div class="layui-input-block">
                    <input type="text" readonly placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单人</label>
                <div class="layui-input-block">
                    <input type="text" name="singleMaker" id="singleMaker" readonly value="hhx123" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单部门</label>
                <div class="layui-input-inline">
                    <select name="departmentId" id="departmentId" lay-verify="required" lay-search lay-filter="demo1select">
                        <option value="1" selected>仓储部</option>
                    </select>
                </div>
            </div>
        </div>
        <hr />

        <br />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="component" class="layui-btn" lay-submit lay-filter="demo-val">
                    保存
                    <i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <!-- 初始显示保存和提交按钮 -->
                <button type="submit" id="saveButton" class="layui-btn layui-icon layui-icon-add-1" lay-submit lay-filter="demo-val">保存</button>
                <button type="button" id="approveButton" class="layui-btn layui-bg-blue" lay-submit lay-filter="demo1-val" onclick="updateState(2)">提交</button>
                <!-- 审核通过按钮和驳回按钮初始隐藏 -->
                <button type="button" id="tongButton" class="layui-btn layui-bg-orange" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(3)">审核通过</button>
                <button type="button" id="boButton" class="layui-btn layui-bg-red" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(4)">驳回</button>
                <button type="button" id="bianButton" class="layui-btn layui-bg-red" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(5)">变更</button>
                <button style="margin-left: 1000px" type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="search">
                    提交<i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
    </form>

    <h3 style="color: #50a5f1">行信息</h3>
    <hr style="color: #50a5f1" />
    <div class="layui-tab" lay-filter="test-hash">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">物料需求列表</li>
            <li lay-id="22">工序计划列表</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-hide" id="ID-table-demo-search"></table>
            </div>
            <div class="layui-tab-item">
                <table class="layui-hide" id="ID-table-demo1-search"></table>
            </div>
        </div>
    </div>

    <script>

        layui.use(['form', 'laydate', 'util','table'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            SearchTaskType()//任务类型
            SearchMaterial()//物料选择
            // 日期
            laydate.render({
                elem: '#date'
            });
            //物料管理添加
            // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });
            // 添加提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值;
                var username=localStorage.getItem('userName');
                console.log(username);
                field.createdOwner = username;
                field.createdTime = "" || new Date().toISOString();
                field.updateOwner = "" || null;
                field.updateTime = "" || new Date().toISOString();
                field.examineOwner = "" || null;
                field.examineTime = "" || new Date().toISOString();
                field.isStatus = 1;
                field.isDel = 1;
                field.auditStatus=1;
                field.singleMaker = username;
                field.departmentId=1;
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite'+"/api/ProductionTasks/CreateProductionTasks",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg ,{ icon: 6, time: 1000 });
                        Seach()//物料需求计划
                        Seach1()//工序计划列表
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });
            
              //任务类型下拉框绑定
            function SearchTaskType() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/ProductionTasks/SearchTaskType",
                    type: 'GET',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.taskTypeId + '">' + item.taskTypeName + '</option>';
                        });
                        $('#taskTypeId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }
            //物料选择下拉框绑定
            function SearchMaterial() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/Process/SearchLogistics",
                    type: 'GET',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.materialId + '">' + item.materialName + '</option>';
                        });
                        $('#materialId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }
            //物料下拉框获取值
            form.on('select(demoselect)', function (data) {
                materialId = data.value;
                console.log(materialId)
                MaterialUnit()//物料单位
                MaterialSpecifications()//物料规格
                SingleMaker()//制单人
                BoMInformId()//物料清单ID
                ProcessRouteId() //工艺路线ID
            });
            //物料单位
            function MaterialUnit() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#materialUnit').val(res.data.materialUnitName);
                    }
                });
            }
            //物料规格
            function MaterialSpecifications() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#materialSpecifications').val(res.data.specifications);
                    }
                });
            }
            //制单人
            function SingleMaker() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#singleMaker').val(localStorage.getItem('userName'));
                    }
                });
            }

             //物料清单ID
            function BoMInformId() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
               $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchBOMInforID",
                    type: 'GET',
                    data:obj,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.boMInformId + '">' + item.boMInformCode + '</option>';
                        });
                        $('#boMInformId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }

            //物料清单下拉框获取值
            form.on('select(demo1select)', function (data) {
                boMInformId = data.value;
                console.log(boMInformId)
                BoMInformVersion()//物料清单版本
            });
            //物料清单版本
            function BoMInformVersion() {
                var boMInformId = $('#boMInformId').val();
                console.log(boMInformId)
                var obj = {
                    BoMInformId: boMInformId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchBOMID",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#boMInformVersion').val(res.data.boMInformVersion);
                    }
                });
            }
             //工艺路线ID
            function ProcessRouteId() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchBOMInforID",
                    type: 'GET',
                    data:obj,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.processRouteId + '">' + item.processRouteName + '</option>';
                        });
                        $('#processRouteId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }
             //工艺路线下拉框获取值
            form.on('select(demo2select)', function (data) {
                processRouteId = data.value;
                console.log(processRouteId)
                ProcessVersion()//工艺路线版本
            });
            //工艺路线版本
            function ProcessVersion() {
                var processRouteId = $('#processRouteId').val();
                console.log(processRouteId)
                var obj = {
                    ProcessRouteId: processRouteId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchProcessRoutesID",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#processVersion').val(res.data.processVersion);
                    }
                });
            }

            // 搜索提交
            function Seach() {
                $.ajax({
                    url:'@ViewBag.RedDragonWrite'+"/api/ProductionTasks/SearchProductionTasks",
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [[
                                { field: 'materialId', title: '序号', width: 80 },
                                { field: 'materialId', title: '顺序', width: 120 },
                                { field: 'materialName', title: '工序', width: 120 },
                                { field: 'materialName', title: '物料', width: 100 },
                                { field: 'specifications', title: '规格', width: 100 },
                                { field: 'specifications', title: '单位', width: 100 },
                                { field: 'productionQuantity', title: '所需数量', width: 100 },
                                { field: 'productionQuantity', title: '领用数量', width: 100 },
                                { field: 'productionQuantity', title: '退回数量', width: 100 },
                                { field: 'productionQuantity', title: '前置期（天）', width: 100 },
                                { field: 'auditStatus', title: '状态', width: 100 },
                                {
                                    fixed: 'right',
                                    title: '操作',
                                    width: 134,
                                    minWidth: 125,
                                    templet: '#toolDemo',
                                },
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
            // 搜索提交
            function Seach1() {
                $.ajax({
                    url:'@ViewBag.RedDragonWrite'+"/api/ProductionTasks/SearchProductionTasks",
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo1-search',
                            cols: [[
                                { field: 'materialId', title: '序号', width: 80 },
                                { field: 'materialId', title: '工序', width: 120 },
                                { field: 'materialName', title: '工作中心', width: 120 },
                                { field: 'productionQuantity', title: '前置期（天）', width: 100 },
                                { field: 'taskTypeName', title: '实际工期（天）', width: 100 },
                                { field: 'productionQuantity', title: '完成数量', width: 100 },
                                { field: 'productionQuantity', title: '合格数量', width: 100 },
                                { field: 'productionQuantity', title: '报废数量', width: 100 },
                                { field: 'productionQuantity', title: '成本费用（元）', width: 100 },
                                {field:'startTime', width:150, title: '计划开工日期',templet: '<div>{{ layui.util.toDateString(d.startTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                {field:'endTime', width:150, title: '计划完工日期',templet: '<div>{{ layui.util.toDateString(d.endTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                { field: 'auditStatus', title: '状态', width: 100 },
                                {
                                    fixed: 'right',
                                    title: '操作',
                                    width: 134,
                                    minWidth: 125,
                                    templet: '#toolDemo',
                                },
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
        })
    </script>

    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="" style="color:cornflowerblue;">编辑</a>
          <br />
          <a onclick="" style="color:red">删除</a>
        </div>
    </script>
</body>
</html>
